<template>
  <!-- 新增类型dialog -->
  <Edialog
    title="分组选择"
    :outershow="show"
    saveClick
    @close="closeFn"
    @saveFn="saveFn"
  >
    <div style="padding: 0 20px">
      <el-form ref="form" :model="form" label-width="80px" :rules="leftRules">
        <el-form-item prop="groupId" label="分组名称">
          <Eselect
            style="width: 100%"
            isClearable
            :options="sendArr"
            :value="form.groupId"
            @EselectChange="form.groupId = $event"
          ></Eselect>
        </el-form-item>
      </el-form>
    </div>
  </Edialog>
</template>

<script>
import Edialog from '@/components/Edialog'
import { getContactsGroupData } from '@/utils/publicReq'
import Eselect from '@/components/Eselect'
import { getBsContacts } from '@/api/smsManage/groupContacts'
export default {
  components: {
    Edialog,
    Eselect
  },
  data () {
    return {
      show: false,
      sendArr: [],
      form: {
        groupId: ''
      },
      leftRules: {
        groupId: [{ required: true, message: '请输入', trigger: 'blur' }]
      }
    }
  },
  methods: {
    async open () {
      this.sendArr = await getContactsGroupData()
      this.show = true
    },
    // 保存事件
    saveFn () {
      this.$refs.form.validate(async valid => {
        if (valid) {
          let res = await getBsContacts({
            groupId: this.form.groupId,
            currPage: 1,
            pageSize: 99999
          })
          if (res.data && res.data.bcode == 0) {
            res.data.bdata.gdata.forEach(item => (item.remark = ''))
            this.$emit('callBackFn', res.data.bdata.gdata)
            this.closeFn()
          }
        }
      })
    },
    closeFn () {
      this.form.groupId = ''
      this.$refs.form.clearValidate()
      this.show = false
    }
  }
}
</script>

<style scoped lang="scss"></style>
